<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <script crossorigin="anonymous" src="/__dist__/botframework-webchat-fluent-theme.production.min.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script type="text/babel">
      run(async function () {
        const {
          React,
          ReactDOM: { render },
          WebChat: { FluentThemeProvider, ReactWebChat }
        } = window; // Imports in UMD fashion.

        const directLine = testHelpers.createDirectLineWithTranscript(
          testHelpers.transcriptNavigation.generateTranscript()
        );
        const store = testHelpers.createStore();

        const App = () => <ReactWebChat directLine={directLine} store={store} />;

        render(
          <FluentThemeProvider>
            <App />
          </FluentThemeProvider>,
          document.getElementById('webchat')
        );
        await pageConditions.uiConnected();
        await pageConditions.numActivitiesShown(32);
        await pageConditions.scrollToBottomCompleted();

        document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`).focus();

        // Should scroll a page up
        await host.sendKeys('PAGE_UP');
        await pageConditions.scrollStabilized();
        await host.snapshot();

        // Should scroll another page up
        await host.sendKeys('PAGE_UP');
        await pageConditions.scrollStabilized();
        await host.snapshot();

        // Should scroll back down
        await host.sendKeys('PAGE_DOWN');
        await pageConditions.scrollStabilized();
        await host.snapshot();

        // Should scroll to the top
        await host.sendKeys('HOME');
        await pageConditions.scrollStabilized();
        await host.snapshot();

        // Should scroll to the bottom
        await host.sendKeys('END');
        await pageConditions.scrollStabilized();
        await host.snapshot();

        // Should not scroll because the send box is not empty
        await host.sendKeys('A', 'PAGE_UP');
        await pageConditions.scrollStabilized();
        await host.snapshot();

        // Should page up because the send box is now empty
        await host.sendKeys('BACK_SPACE', 'PAGE_UP');
        await pageConditions.scrollStabilized();
        await host.snapshot();
      });
    </script>
  </body>
</html>
